package com.ruoyi.project.system.controller;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.project.system.domain.SysExam;
import com.ruoyi.project.system.service.ISysExamService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api("检查费用")
@RestController
@RequestMapping("/system/exam")
public class SysExamController extends BaseController {

    @Autowired
    private ISysExamService examService;

    /**
     * 获取部门列表
     */
    @ApiOperation("查询项目信息")
    @GetMapping("/list")
    public AjaxResult list(SysExam exam)
    {
        List<SysExam> exams = examService.selectExamList(exam);
        return AjaxResult.success(exams);
    }

    @ApiOperation("查询单个项目信息")
    @GetMapping(value = "/{examId}")
    public AjaxResult getInfo(@PathVariable("examId") Long examId)
    {
        return AjaxResult.success(examService.selectExamById(examId));
    }

    @ApiOperation("新增项目信息")
    @Log(title = "新增项目信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody SysExam exam)
    {
        exam.setCreateBy(SecurityUtils.getUsername());
        exam.setCreateTime(DateUtils.getNowDate());
        return toAjax(examService.insertExam(exam));
    }

    @ApiOperation("修改项目信息")
    @Log(title = "修改项目信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysExam exam)
    {
        exam.setUpdateBy(SecurityUtils.getUsername());
        exam.setUpdateTime(DateUtils.getNowDate());
        return toAjax(examService.updateExam(exam));
    }

    @ApiOperation("删除项目信息")
    @Log(title = "删除项目信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(examService.deleteExamByIds(ids));
    }
}
